package xyz.xuminghai.javafx_learn.animation.transition;

import javafx.animation.StrokeTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * 2023/7/30 7:35 星期日<br/>
 * 此Transition会创建一个动画，该动画会在duration内更改形状的描边颜色。
 * 这是通过定期更新shape的stroke变量来完成的
 *
 * @author xuMingHai
 */
public class StrokeTransitionApp extends Application {


    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }


    @Override
    public void init() {
        Rectangle rectangle = new Rectangle(100.0, 100.0, Color.TRANSPARENT);
        rectangle.setStrokeWidth(5.0);

        StrokeTransition strokeTransition = new StrokeTransition(Duration.millis(3000.0), rectangle,
                Color.RED, Color.BLUE);
        strokeTransition.play();

        root.setCenter(rectangle);
    }


    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}

